package com.zxs.user.controller;

/**
 * @author zxs
 * *9 15:52
 */

import com.zxs.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import parm.CartListParm;
import parm.PageParam;
import pojo.User;
import utils.R;

/**
 * 后台查询用户列表
 */
@RestController
@RequestMapping("user")
public class UserAdminController {

    @Autowired
    private UserService userService;

    @PostMapping("admin/list")
    public R list(@RequestBody @Validated PageParam pageParam, BindingResult result){
        if (result.hasErrors()){
            return R.fail("用户列表查询失败");
        }
        return userService.list(pageParam);
    }
    @PostMapping("admin/remove")
    public R remove(@RequestBody @Validated CartListParm cartListParm, BindingResult result){
        if (result.hasErrors()){
            return  R.fail("用户删除失败");
        }
        return userService.remove(cartListParm.getUserId());
    }
    @PostMapping("admin/update")
    public R update(@RequestBody User user){
        return userService.update(user);
    }

    @PostMapping("admin/save")
    public R save(@RequestBody User user){
        return userService.save(user);
    }

}
